<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>仿微信摇一摇</title>
<style type="text/css" media="screen">
.shake-mask{position: absolute;top: 0;left: 0;height: 100%;width: 100%;display: block;text-align: center;display: none;z-index: 9999;}
.shake-mask .top,.shake-mask .bottom{background-image: url(./images/shake_bg.png);background-color: #282C2D}
.shake-mask .top{height:50%;display: none;position: relative;overflow: hidden;-webkit-transform:translateY(-100%);}
.shake-mask .top img{position: absolute;bottom: -102px}
.shake-mask .bottom{height:50%;display: none;position: relative;overflow: hidden;-webkit-transform:translateY(100%);}
.shake-mask .bottom img{position: absolute;top: -102px}

.shake-mask .top.shaking{-webkit-animation:upAnimation .9s 1;display: block;}
.shake-mask .bottom.shaking{-webkit-animation:downAnimation .9s 1;display: block;}
@-webkit-keyframes upAnimation
{
	0%   {-webkit-transform:translateY(-100%);}
	50%  {-webkit-transform:translateY(0);}
	100% {-webkit-transform:translateY(-100%);}
}

@-webkit-keyframes downAnimation
{
	0%   {-webkit-transform:translateY(100%);}
	50%  {-webkit-transform:translateY(0);}
	100% {-webkit-transform:translateY(100%);}
}
</style>
<script type="text/javascript" src="./js/jquery.min.js"></script>
<script type="text/javascript" src="./js/shake.js"></script>
</head>
<body>
<div class="shake-mask">
	<div class="top"><img src="./images/shake_hand.png" width="200"></div>
	<div class="bottom"><img src="./images/shake_hand.png" width="200"></div>
</div>
<script type="text/javascript">	
	var myShakeEvent = new Shake({
	    threshold: 5, // optional shake strength threshold
	    timeout: 300 // optional, determines the frequency of event generation
	});
	myShakeEvent.start();

	var $oShake = $('.shake-mask'), shakeTimer;

	$('div img', $oShake).css({'left':($(window).width()-200)/2});

	var shakeStart = function() {
		$oShake.show().find('.top,.bottom').addClass('shaking');
	}

	var shakeEnd = function() {
		$oShake.hide().find('.top,.bottom').removeClass('shaking');
	}

	var showShake = function() {
		shakeStart();
		shakeTimer && clearTimeout( shakeTimer );
		shakeTimer = setTimeout( shakeEnd, 900 );
	}
	
	window.addEventListener('shake', function(){
		showShake();
	}, false)
</script>
<a href="javascript:showShake();void(0);">仿微信摇一摇</a>
</body>
</html>